﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace QuanLiBongDa.DataAccessLayer
{
    class CauThuDAO
    {
        public static CauThuDAO CreateCauThuDAO()
        {
            return new CauThuDAO();
        }
        public bool Insert_CauThu(CauThuDTO c)
        {
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaCT", c.MaCT);
            par[1] = new SqlParameter("@TenCT", c.TenCT);
            par[2] = new SqlParameter("@MaDoi",c.MaDoi);
            par[3] = new SqlParameter("@NgaySinh",c.NgaySinh);
            par[4] = new SqlParameter("@MaLCT",c.MaLCT);
            par[5] = new SqlParameter("@GhiChu", c.GhiChu);
            return SQLService.mmExecuteNonquery("Insert_CauThu", par);
        }
        public bool Update_CauThu(CauThuDTO c)
        {
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaCT",c.MaCT);
            par[1] = new SqlParameter("@TenCT",c.TenCT);
            par[2] = new SqlParameter("@MaDoi",c.MaDoi);
            par[3] = new SqlParameter("@NgaySinh",c.NgaySinh);
            par[4] = new SqlParameter("@MaLCT",c.MaLCT);
            par[5] = new SqlParameter("@GhiChu",c.GhiChu);
            return SQLService.mmExecuteNonquery("Update_CauThu",par);
        }
        public bool Delete_CauThu(CauThuDTO c)
        {
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@MaCT", c.MaCT);
            return SQLService.mmExecuteNonquery("Delete_CauThu", par);
        }
        public void MaDoi(ComboBox madoi)
        {
            SqlDataReader dr = SQLService.mExecuteReader(SQLService.ReturnAll("DOIBONG"));
            while (dr.Read())
            {
                madoi.Items.Add(dr["TenDoi"]);
            }
        }       
        public DataTable TimMCT_Ten(string tenloai)
        {
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("TenCT", tenloai);
            return SQLService.FillTable("TimMCT_Ten", par);
        }
        public void MaCT(ComboBox mact)
        {
            SqlDataReader dr = SQLService.mExecuteReader(SQLService.ReturnAll("CAUTHU"));
            while (dr.Read())
            {
                mact.Items.Add(dr["TenCT"]);
            }
        }
        
        //public bool TestCTTT(CauThuDTO c)
        //{
        //    SqlParameter[] par = new SqlParameter[1];
        //    par[0] = new SqlParameter("@MaDoi",c.MaCT);
        //    return SQLService.mmExecuteNonquery("TestCTTT", par);
        //}
    }
}
